# Copyright (c) 2008 Alvin Wang http://cloudwizard.com/
# License New BSD
# See README for additional information

"""Dreamhost Cloud Support"""

from cloudwizard.cloud import Cloud
from cloudwizard.compute import ComputeService
from cloudwizard.ssh import Connection
from cloudwizard.config import Config

class Compute(ComputeService):	# encapsulate connection
    """ComputeService API
    """

    def __init__(self, auth=None, username='default', **args):
        if auth:
            self.cloud_auth=auth
        else:
            self.cloud_auth = Config( cloud_abbrev = 'dreamhost', 
                config_name=username, type='user')

    def olist(self, status=None):
        """list all live domains"""
        c = Connection(self.cloud_auth.data['system'], 
            username=self.cloud_auth.data['username'], 
            password=self.cloud_auth.data['password'])
        result = c.execute("ls")
        c.close()
        arr=[]
        for a in result:
            b = a.strip()
            if b =='Maildir':
                pass
            else:
                if b=='logs':
                    pass
                else:
                    arr.append( b)
        return arr
        
    def plist(self, status=None):
        """list all live domains"""
        result = self.olist()
        for d in result:
            print d
        """    
    instances=[]
    reservations = self.ec2_connection.get_all_instances()
    for reservation in reservations:
    for instance in reservation.instances:
    instances.append(instance)
    return instances
    """